/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package testing;

import cfar.ff.data.Assocs.Assoc2;
import cfar.ff.data.List;
import cfar.ff.fun.F1;
import cfar.ff.fun.Seq;
import cfar.ff.interfaces.Sequence;


import cfar.ff.data.Stream;

/**
 *
 * @author haoyun
 */
public class redunVSaccu {
    
    public static void main (String[] args){
        List<Double> s1 = List.list(1.0,2.0,3.0,4.0,5.0,6.0);
        Stream<Integer> reds = Stream.stream(2,2,2,2,2,2,2,2,2,2);
        Sequence s2 = Seq.parRMap(choose, reds, trajMapper, s1);
        System.out.println(s2);
    }

    static F1<Double, List<Double>> trajMapper = new F1<Double, List<Double>>() {

        public List<Double> f(Double a) {
            return Eval.genTrajMap(a);
        }
    };


        static F1<Sequence<Stream,List<Double>>, List<Double>> choose = new F1<Sequence<Stream, List<Double>>, List<Double>>() {

            public List<Double> f(Sequence<Stream, List<Double>> a) {
                Sequence<Stream,Assoc2<Boolean,List<Double>>> tmp =  Seq.parMap(status, a);
                for(Assoc2<Boolean, List<Double>> status : tmp){
                    if(status.$1)
                        return status.$2;
                }
                return tmp.head().$2;
            }
        };

        static F1<List<Double>, Assoc2<Boolean,List<Double>>> status = new F1<List<Double>, Assoc2<Boolean, List<Double>>>() {

            public Assoc2<Boolean, List<Double>> f(List<Double> a) {
//                List<Double> l = (List<Double>) Seq.mkSeq(a, List.<Double>nil());
                return new Assoc2<Boolean, List<Double>>(checkRange.f(a), a);
            }
        };

        static F1<List<Double>, Boolean> checkRange = new F1<List<Double>, Boolean>() {

            public Boolean f(List<Double> a) {
                for(Double d : a){
                    if (d < -2 || d > 2) return false;
                }
                return true;
            }
        };

}
